<script src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js" ></script>

<div class="container">
  <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
    <a class="navbar-brand mx-4" href="/wx">微信公众平台辅助</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarText">
      <ul class="navbar-nav mr-auto">
        <li class="nav-item">
            <a class="nav-link" href="https://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index" target="_blank">测试号管理</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="https://gitee.com/chenrh/finego">源代码</a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">Pricing</a>
        </li>
      </ul>
      <span class="navbar-text text-dark">
      </span>
    </div>
  </nav>

<div class="card-columns mt-1">
  <div class="card">
    <div class="card-body">
      <h5 class="card-title">tokencheck</h5>
      <p class="card-text">
        请填写接口配置信息，此信息需要你有自己的服务器资源，填写的URL需要正确响应微信发送的Token验证，请阅读
        <a href="https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Access_Overview.html" target="_blank">消息接口使用指南</a>
      </p>
    </div>
    <div class="card-footer"><a href="/wx/tokencheck">/wx/tokencheck</a></div>
  </div>

  <div class="card">
    <div class="card-body">
      <h5 class="card-title">access_token</h5>
      <p class="card-text">
        access_token是公众号的全局唯一接口调用凭据，公众号调用各接口时都需使用access_token。开发者需要进行妥善保存。access_token的存储至少要保留512个字符空间。access_token的有效期目前为2个小时，需定时刷新，重复获取将导致上次获取的access_token失效。
        <a href="https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_access_token.html">获取access_token</a>
      </p>
      <p class="text-success">
        {{.AccessToken}}
      </p>
    </div>
  </div>
  <!--自定义菜单-->
  <div class="card">
    <div class="card-body">
      <h5 class="card-title"><small><a href="https://developers.weixin.qq.com/doc/offiaccount/Custom_Menus/Creating_Custom-Defined_Menu.html" target="_blank">自定义菜单</a></small></h5>
      <p class="text-danger">不允许创建链接链到别人的小程序和公众号</p>
      <form method="POST">
        <div class="form-group">
          <label for="MENU">菜单JSON</label>
          <textarea class="form-control" id="TEXTAREA_MENU" rows="10"> {
            "button":[
             {	
                 "type":"click",
                 "name":"今日歌曲",
                 "key":"V1001_TODAY_MUSIC"
             },
             {
                  "name":"菜单",
                  "sub_button":[
                  {	
                    "type":"view",
                    "name":"网站首页",
                    "url":"{{.SiteUrl}}"
                  },
                  {	
                    "type":"view",
                    "name":"微信助手",
                    "url":"{{.SiteUrl}}/wx"
                  },
                  {	
                    "type":"view",
                    "name":"测试位置",
                    "url":"{{.SiteUrl}}/wx/location"
                  },
                  {	
                    "type":"view",
                    "name":"测试分享",
                    "url":"{{.SiteUrl}}/wx/share"
                  }]
              }]
        }</textarea>
        </div>
        <div class="mt-4">
            <button type="button" id="TEXTAREA_MENU_BUTTON" class="btn btn-primary">发送</button>
        </div>
      </form>
    </div>
  </div>

  <!--模板消息-->
  <div class="card">
    <div class="card-body">
      <h5 class="card-title"><small><a href="https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Template_Message_Interface.html#5" target="_blank">模板消息</a></small></h5>
      <div class="mt-4">
        <button type="button" id="POST_TEMPLATE_MSG_BUTTON" class="btn btn-primary">发送默认模板消息</button>
      </div>

      <h5 class="card-title my-4"><small><a href="https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html#49" target="_blank">扫一扫</a></small></h5>
      <div class="mt-4">
        <button type="button" id="WX_SAOYISAO" class="btn btn-primary">调用扫一扫</button>
      </div>

      <h5 class="card-title my-4"><small><a href="https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html#38" target="_blank">地理位置</a></small></h5>
      <div class="mt-4">
        <button type="button" id="WX_LACATION" class="btn btn-primary">我的地理位置</button>
      </div>
    </div>
  </div>
</div>

</div>

<script>
    $(function(){
        var config = {{.WxJssdkConfig}};
        wx.config({
            debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
            appId: config.appid, // 必填，公众号的唯一标识
            timestamp: config.timestamp, // 必填，生成签名的时间戳
            nonceStr: config.nonceStr, // 必填，生成签名的随机串
            signature: config.signature,// 必填，签名
            jsApiList: ["scanQRCode","getLocation"] // 必填，需要使用的JS接口列表
        });

        $("#TEXTAREA_MENU_BUTTON").on("click", function(){
            var menudata = $("#TEXTAREA_MENU").val();
            $.post("/wx/postmenu", {menu: menudata}, function(json){
                  if(json.flag){
                      alert(json.msg);
                  }else{                    
                      alert(json.msg);
                  }
            })
        });

        $("#POST_TEMPLATE_MSG_BUTTON").on("click", function(){
            window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid={{.Appid}}&redirect_uri={{.SiteUrl}}/wx/authorize&response_type=code&scope=snsapi_base&state=/wx/dft_temp_msg#wechat_redirect'
        });

        $("#WX_LACATION").on("click", function(){
          wx.getLocation({
              type: 'wgs84', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
              success: function (res) {
                  var latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
                  var longitude = res.longitude; // 经度，浮点数，范围为180 ~ -180。
                  var speed = res.speed; // 速度，以米/每秒计
                  var accuracy = res.accuracy; // 位置精度
                  alert("latitude="+ latitude + "longitude="+longitude);
              }
          });
        });

        $("#WX_SAOYISAO").on("click",function(){
          alert('您点击了扫一扫');
          wx.scanQRCode({
            needResult: 0, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
            scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
            success: function (res) {
              var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
            }
          });
        })
    });
</script>